﻿<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@ page import="java.sql.*" %>
     <table width="100%" border="0" cellpadding="0" cellspacing="0">
                 <tr>
                   <td height="50" style="background:url(images/lanbt.gif) no-repeat" ><table width="100%" border="0">
                     <tr>
                       <td width="20%" height="26" valign="bottom" class="redbt">&nbsp;&nbsp;&nbsp;&nbsp;下载专区</td>
                       <td width="80%" align="right" valign="bottom"  class="locationstr"><a href="<%=basePath%>">首页 </a>&gt 文件下载 &nbsp;</td>
                     </tr>
                   </table></td>
                 </tr>
      </table>
  <table width="99%" border="0" cellpadding="8" align="right">
         <% 
   Data data=new Data(dbuser,dbpass,dburl);
   //分页段 
     //变量声明 
String mysql=new String(); //SQL语句

String fcid=request.getParameter("fcid");
String fid=request.getParameter("fid");
String where="";
if(!("".equals(fcid) || fcid==null)){
  mysql=" web_file where fid>0";
  where = where+" and fcid="+fcid; 
}else if(!("".equals(fid) || fid==null)){
  mysql=" web_filelist where flid>0";
  where = where+" and fid="+fid; 
}else{
 mysql=" web_file where fid>0";
}

int intRowCount=0;  //总的记录数
int intPageCount=0; //总的页数
int intPageSize=15; //每页显示的记录数
int intPage; //待显示页码 
String strPage=new String(); //用来接收当页码参数
int begin_no=0; //开始的rownum记录号
int end_no=0;  //结束的rownum记录号

//取得待显示页码 
strPage = request.getParameter("pages"); 
if(strPage==null){//表明在QueryString中没有page这一个参数，此时显示第一页数据 
intPage = 1; 
} 
else{//将字符串转换成整型 
intPage = java.lang.Integer.parseInt(strPage); 
if(intPage<1) intPage = 1; 
} 
//得到总的数据记录行数
intRowCount=data.getRowCount(mysql); //总记录数

//计算总共要分多少页
intPageCount = (intRowCount+intPageSize-1) / intPageSize; 
//调整待显示的页码 

if(intPage>intPageCount) intPage = intPageCount; 
//分页段
         begin_no=(intPage-1) * intPageSize + 1; 
        end_no = intPage * intPageSize;
        
        if(!("".equals(fcid) || fcid==null)){
         mysql="select * from (select rownum row_id,fid,title,filepath,nums,addtime,ver,info from (select  fid,title,filepath,nums,addtime,ver,info from web_file where fcid="+fcid+" order by fid desc))";
	    mysql=mysql+" where row_id between " +begin_no+ " and " +end_no;
		}else if(!("".equals(fid) || fid==null)){
		mysql="select * from (select rownum row_id,flid,fid,title,filepath,addtime,ver,info from (select  flid,fid,title,filepath,addtime,ver,info from web_filelist where fid="+fid+" order by fid desc))";
	    mysql=mysql+" where row_id between " +begin_no+ " and " +end_no;
		}else{
		  mysql="select * from (select rownum row_id,fid,title,filepath,nums,addtime,ver,info from (select  fid,title,filepath,nums,addtime,ver,info from web_file  order by fid desc))";
	      mysql=mysql+" where row_id between " +begin_no+ " and " +end_no;
		}
		
	    ResultSet rsc=con.getRs(mysql);
		int i=0;
try{
        String otm="";
		String filepath="";
		String ofid="";
		while(rsc.next()){
		i++;
		otm=rsc.getString("info");
		filepath=rsc.getString("filepath");
		ofid=rsc.getString("fid");
		if(!("".equals(filepath) || filepath==null)){
		  filepath=basePath+filepath;
		}else{
		  filepath=basePath+"download.jsp?fid="+ofid;
		}
        %>
	      <tr>
             <td class="infolist">
             <div><span style="float:left;"><%=rsc.getString("title") %><%=rsc.getDate("addtime") %></span><span style="float:right;"><a href="<%=filepath%>" >下载</a></span></div>              
             </td>
           </tr>
            <% if(!("null".equals(otm) || "".equals(otm) || otm==null)){%>
            <tr>
             <td class="infolist" style="background:#EEEEEE">
             <%=otm %>
             </td>
           </tr>
            <% }%>
      <%} %>
           <%if(intPageCount>1){ %>
            <tr>
             <td align="center"> <div class="pagelist"><%
             String pagehtml=con.getPage(intPage,intRowCount,intPageCount,"?fcid="+fcid+"&fid="+fid);
             out.print(pagehtml);
 %>         </div></td>
           </tr>
           <%} %>
     </table>
<% rsc.close();
}catch(Exception e){ }
%>
